import { createSlice } from '@reduxjs/toolkit'

interface CounterState {
	value: number
}
export const counterSlice = createSlice({
	name: 'counter',
	initialState: {
		value: 0
	} as CounterState,
	reducers: {
		increment: (state) => {
			state.value += 1
		},
		decrement: (state) => {
			state.value -= 1
		},
		incrementByAmount: (state, action) => {
			state.value += action.payload
		}
	}
})
// 每个 case reducer 函数会生成对应的 Action creators
export const { increment, decrement, incrementByAmount } = counterSlice.actions
const reuders = counterSlice.reducer
export default reuders
